/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package generator;

import generator.connection.KillThread;
import java.awt.Color;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;

/**
 *
 * @author abosancic
 */
public class BlinkLabel extends JLabel implements Runnable{

    public Thread thread;
    
    private int counter = 0;
    private int sleep = 0;
    private Color color = null;
    
    public BlinkLabel(String name, int blinkNumber) {
        this(name, blinkNumber, 500, null);
    }
    
    public BlinkLabel(String name, int blinkNumber, int sleep) {
        this(name, blinkNumber, sleep, null);
    }
    
    public BlinkLabel(String name, int blinkNumber, int sleep, Color color) {
        this.thread = new Thread(this, name);
        this.counter = blinkNumber;
        this.sleep = sleep;
        if(color == null){
            this.color = Color.green;
        }else{
            this.color = color;
        }
        
        this.thread.start();
    }
    
    @Override
    public void run() {
        
        int tmpCount = 0;
        
        while (true && (counter > tmpCount)) {
            if (tmpCount % 2 == 0) {
                this.setForeground(this.color);
                this.setVisible(true);
            } else {
                this.setVisible(false);
            }
            
            tmpCount++;
            
            try {
                Thread.sleep(this.sleep);
            } catch (InterruptedException ex) {
                Logger.getLogger(BlinkLabel.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        
        new KillThread(this.getParent(), this);
    }

    public int getCounter() {
        return counter;
    }

    public void setCounter(int counter) {
        this.counter = counter;
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        this.color = color;
    }
    
    

}
